%% ROISTATS FUNCTION
% Author: Mathieu Boudreau
% Date Created: March 20rd 2012
% Date Modified: April 17th 2012 by Mathieu Boudreau
% 
% User selects a region of interest on the current figure, and
% function outputs the standard deviation and mean of the ROI.
%
% ***Rectangle must be chosen by clicking and dragging toward the right
% and down***


function [stdRoi,meanRoi] = roiStats(imageData)
    
    % Load image
    figure()
    imagesc(imageData)
    
    % Select regoin of interest
    h = imrect;
    position = wait(h);  
    delete(h)
    matRoi = imageData(round(position(2)):round((position(2)+position(4))),round(position(1)):round((position(1)+position(3))));
    
    % Calculate statistical values
    stdRoi = std2(matRoi);
    meanRoi = mean2(matRoi);
end

